﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UFIDA.U9.Base.FlexField.ValueSet;
using UFIDA.U9.MO.Enums;
using UFIDA.U9.MRP.Enums;
using UFIDA.U9.SM.Ship;
using UFIDA.U9C.Cust.ZL.PlugBE.Tool;
using UFSoft.UBF.Business;
using UFSoft.UBF.Eventing;

namespace UFIDA.U9C.Cust.ZL.PlugBE
{
    /// <summary>
    /// 生产订单备料表 真兰    
    /// </summary>
    class MOInsertZLExtend : IEventSubscriber
    {
        public void Notify(params object[] args)
        {
            if (args == null || args.Length == 0 || !(args[0] is UFSoft.UBF.Business.EntityEvent))
                return;
            BusinessEntity.EntityKey key = ((UFSoft.UBF.Business.EntityEvent)args[0]).EntityKey;
            if (key == null)
                return;
            UFIDA.U9.MO.MO.MO entity = key.GetEntity() as UFIDA.U9.MO.MO.MO;
            if (entity == null)
                return;
            try
            {
                //保持生产订单入库组织=货主组织 
                if (PubWebClass.IsOpenPlug())
                {
                    if (entity.OriginalData.ID == 0)
                    {
                        if (entity.CompleteInOrg != entity.OwnerOrg)
                        {
                            entity.CompleteInOrg = entity.OwnerOrg;
                        }
                        //如果入库组织！=当前组织 则将入库存储地点默认为空 SCVWh
                        if (entity.CompleteInOrg != entity.Org && entity.SCVWh != null)
                        {
                            entity.SCVWh = null;
                            entity.SCVWhKey = null;
                        }
                    }

                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

        }
    }
}
